package com.ruoyi.web.wx.controller;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.wx.service.IPtExpService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author moxiu
 * @since 2021-11-13
 */
@RestController
@RequestMapping("/wx/ptExp")
public class PtExpController {
	@Autowired
	private IPtExpService iPtExpService;

	@Autowired
	private ISysDeptService deptService;

	@Autowired
	private ISysUserService iSysUserService;

	@GetMapping("/selectClass")
	@ApiOperation("查看所有的班级")
	public AjaxResult selectClass(){
		List<SysDept> deptList = iPtExpService.selectClassList();
		return AjaxResult.success(deptService.buildDeptTreeSelect(deptList));
	}

	@GetMapping("/chooseClass")
	@ApiOperation("选择班级")
	public AjaxResult chooseClass(Long deptId) {
		final SysUser user = SecurityUtils.getLoginUser().getUser();
		user.setDeptId(deptId);
		iSysUserService.updateDeptId(user);
		return AjaxResult.success("选择班级成功");
	}

	@GetMapping("/allExp")
	@ApiOperation("学生查询当前需要做的实验")
	public AjaxResult homeExp() {
		return AjaxResult.success(iPtExpService.allExp());
	}
}
